package day06;

import java.util.Arrays;

public class Demo01求数组最大最小值 {
    public static void main(String[] args) {
        int[] arr = {1, 342, 34654, 6, 2, 2, 121, 3321};

        int max = arr[0];
        int min= arr[arr.length-1];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        for (int i1=arr.length-1;i1>=0;i1--){
            if (arr[i1]<min){
                min=arr[i1];
            }
        }
        }
        System.out.println("最大值为" + max);
        System.out.println("最小值为"+min);

        //扩容
        arr=Arrays.copyOf(arr,arr.length+1);
        //将max的值赋值给最后一个索引
        arr[arr.length-1]=max;
        System.out.println(Arrays.toString(arr));
    }
}